package h0803;

import java.util.*;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 最富裕的小家庭
 * @date 2024/8/3 15:05
 */
public class RichestSmallFamily {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        //TODO 这个题可能有点瑕疵
        Map<Integer, Integer> map = new HashMap<>();
        while (sc.hasNextInt()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            Integer value = map.get(a);
            if (value == null) {
                value=(arr[a-1]+arr[b-1]);
            } else {
                value+=arr[b-1];
            }
            map.put(a,value);
        }

        Integer max = map.values().stream().max(Integer::compareTo).orElse(0);
        System.out.println(max);
    }
}
